#include <bits/stdc++.h>
// 2025/02/03
// tag: 
// Author: Zhang Muen
using namespace std;

int n, presum[100001];

signed main()
{
    cin >> n;
    for (int i = 1; i <= n; i++){
        int type;
        cin >> type;
        presum[i] = presum[i - 1] + (type == 1 ? 1 : -1);
    }
    unordered_map<int, int> um;
    um[0] = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++){
        int tmp = presum[i];
        if (um.find(tmp) == um.end())
            um[tmp] = i;
        else
            ans = max(ans, i - um[tmp]);
    }
    cout << ans << endl;
    return 0;
}